home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 726-750 / 750 / splitq / splitq.c < prev   
C/C++ Source or Header  |  1995-03-18  |  3KB  |  89 lines

  1. /*****************************************************************************\
  2.  * $VER: SplitQ.c 1.1                 DICE/LATTICE C/SAS C/AZTEC C + AmigaOS *
  3.  *                 _                                                         *
  4.  *            _   // (c)1992 by "Quarky" Dieter Temme                        *
  5.  *            \\ //                                                          *
  6.  * .ts=4       \X/ --- Freeware --- ONLY AMIGA MAKES IT POSSIBLE             *
  7.  *                                                                           *
  8.  * SplitQ splits a file at requested byte offset (like BASIC MID$ function). *
  9. \*****************************************************************************/
  10.  
  11. #define PRGNAME "SplitQ"
  12. #define VERSION "1.1"
  13. #define PRGDATE "27.8.92"
  14.  
  15. #include "amigacompq.h"
  16.  
  17. #include <stdlib.h>
  18. #include <clib/dos_protos.h>
  19. #include <clib/exec_protos.h>
  20. #include <dos/dos.h>
  21. #include <exec/memory.h>
  22.  
  23. #ifdef PRAGMAS_
  24.  #include <pragmas/dos_lib.h>
  25.  #include <pragmas/exec_lib.h>
  26. #endif
  27.  
  28. #ifdef LATTICE
  29.  int CXBRK(void) { return 0; }  /* Disable Lattice CTRL-C handling */
  30.  int chkabort(void) { return 0; }
  31. #endif
  32.  
  33. #ifdef AZTEC_C
  34.  void _wb_parse(void) {}
  35.  void _abort(void) {}
  36. #endif
  37.  
  38. TEXT VersionString[]= "\0$VER: " PRGNAME " " VERSION " (" PRGDATE ")";
  39.  
  40. #define ARG_SRC 1
  41. #define ARG_DST 2
  42. #define ARG_OFS 3
  43. #define ARG_LEN 4
  44.  
  45. int main(int argc, TEXT *argv[])
  46. {    struct FileInfoBlock fib;
  47.     BPTR file= NULL, lock;
  48.     UBYTE *buffer= NULL;
  49.     LONG offset, length= 0;
  50.     UBYTE rc= RETURN_FAIL;
  51.  
  52.     if ((argc == 2) && (argv[1][0] == '?') && !argv[1][1])
  53.     {    Write(Output(), "Usage: SplitQ src/A dest/A offset/N/A length/N\n"
  54.                         "       splits file at offset into two files\n", 91);
  55.         return RETURN_OK;
  56.     }
  57.  
  58.     switch(TRUE)
  59.     {    default:
  60.             if ((argc < 4) || (argc > 5))
  61.             {    Write(Output(), "SplitQ: too few/many arguments\n", 31);
  62.                 break;
  63.             }
  64.             if ((offset= atol(argv[ARG_OFS])) < 0) break;
  65.             if (argc == 5) if ((length= atol(argv[ARG_LEN])) < 0) break;
  66.             if (!(lock= Lock(argv[ARG_SRC], ACCESS_READ))) break;
  67.             if (!Examine(lock, &fib))
  68.             {    UnLock(lock);
  69.                 break;
  70.             }
  71.             UnLock(lock);
  72.             if (fib.fib_DirEntryType > 0) break;
  73.             if (argc == 4) if ((length= fib.fib_Size-offset) < 0) break;
  74.             printf("%d\n", length);
  75.             if (!(buffer= AllocMem(length, MEMF_PUBLIC))) break;
  76.             if (!(file= Open(argv[1], MODE_OLDFILE))) break;
  77.             Seek(file, offset, OFFSET_BEGINNING);
  78.             if (Read(file, buffer, length) < length) break;
  79.             Close(file);
  80.             if (!(file= Open(argv[ARG_DST], MODE_NEWFILE))) break;
  81.             if (Write(file, buffer, length) < length) break;
  82.             rc= RETURN_OK;
  83.     }
  84.     if (buffer) FreeMem(buffer, length);
  85.     if (file) Close(file);
  86.  
  87.     return (int)rc;
  88. }
  89.